package com.happy.common.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class SubString extends TagSupport {
	private String value;
	private int length;
	private String isShow;


	public String getIsShow() {
		return isShow;
	}

	public void setIsShow(String isShow) {
		this.isShow = isShow;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public int doStartTag() throws JspException {
		if (value.length() > length) {
			if (isShow.equals("true")) {
				try {
					pageContext.getOut().write(value.substring(0, length));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				pageContext.setAttribute("value", value.substring(0, length));
			}

		} else {
			if (isShow.equals("true")) {
				try {
					pageContext.getOut().write(value);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				pageContext.setAttribute("value",value);
			}
		}
		return EVAL_PAGE;
	}
}
